<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>素材管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<style>
	.newspreview{width:312px}
	.newspreview *{box-sizing: border-box;}
	.newscontent{padding:12px;border:1px solid #ddd;}
	.item1{width:100%;cursor:pointer}
	.item1 img{width:100%;height:100%}
	.item1 .title{height:40px;padding:0 10px;width:100%;position:absolute;bottom:0;left:0;color:#fff;background:rgba(100,100,100,0.5);display:flex;align-items:center;word-wrap: break-word;word-break: break-all;overflow:hidden;}
	.item2{width:100%;cursor:pointer;margin-top:5px;padding-top:5px;border-top:1px solid #ddd;display:flex}
	.item2 .title{flex:1;display:flex;align-items:center;}
	.item2 img{width:50px;height:50px}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-header">选择素材</div>
          <div class="layui-card-body" pad15>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{:url('sourcelist')}" //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
			//{type:"checkbox"},
      //{field: 'media_id', title: '素材ID',width:180},
      {field: 'content', title: '素材内容',width:350,templet:function(d){
				var news_item = d.content.news_item;
				var html ='<div style="width:312px;padding:12px;border:1px solid #ddd">';
				for(var i in news_item){
					var m = news_item[i]
					if(i==0){
						html+='<div onclick="showqr(\''+m.url+'\',\''+m.title+'\')" style="width:100%;cursor:pointer">';
						html+='<div style="position:relative"><img src="'+m.thumb_url+'" style="width:288px;height:160px;max-width:288px"/><div style="height:40px;padding:0 10px;width:100%;position:absolute;bottom:0;left:0;color:#fff;background:rgba(100,100,100,0.5);display:flex;align-items:center;word-wrap: break-word;word-break: break-all;overflow:hidden;">'+m.title+'</div></div>';
						html+='';
						html+='</div>';
					}else{
						html+='<div onclick="showqr(\''+m.url+'\',\''+m.title+'\')" style="width:100%;cursor:pointer;margin-top:5px;padding-top:5px;border-top:1px solid #ddd;display:flex">';
						html+='<div style="flex:1;display:flex;align-items:center;">'+m.title+'</div>';
						html+='<div><img src="'+m.thumb_url+'" style="width:50px;height:50px"/></div>';
						html+='</div>';
					}
				}
				html+='</div>';
				return html;
      }},
      {field: 'need_open_comment', title: '评论功能',templet:function(d){
				if(d.need_open_comment==1){
					if(d.only_fans_can_comment==1){
						return '粉丝才可以评论'
					}else{
						return '所有人都可以评论';
					}
				}else{
					return '未开启评论';
				}
      }},
      {field: 'create_time', title: '创建时间',templet:function(d){ return date('Y-m-d H:i',d.content.create_time)}},
      {field: 'update_time', title: '更新时间',templet:function(d){ return date('Y-m-d H:i',d.content.update_time)}},
      {field: 'operation', title: '操作',templet:function(d){
				html = '<button class="table-btn" onclick="choosesource(\''+d.media_id+'\')">选择</button></div>';
				return html;
      }}
    ]]
  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	function choosesource(media_id){
		window.parent.choosesource(media_id);
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}
	</script>
</body>
</html>